;---------------------------------------------------------------------
; dkstatementtable.S - table of statement names and handler functions for DK-BASIC - Chris Gerlinsky, 2009
;---------------------------------------------------------------------

.nolist
#include <avr/io.h>	// Include device specific definitions.
.list


;---------------------------------------------------------------------
; FLASH - constants (in code segment)

.section .text

.global dkstatementtable
dkstatementtable:
.string "rem"							; REM
.word	dkstatement_rem
.string "let"							; LET
.word	dkstatement_let
.string "if"							; IF
.word	dkstatement_if
.string "print"							; PRINT
.word	dkstatement_print
.string "?"								; ? (PRINT)
.word	dkstatement_print
.string "input"							; INPUT
.word	dkstatement_input
.string "for"							; FOR
.word	dkstatement_for
.string "next"							; NEXT
.word	dkstatement_next
.string "while"							; WHILE
.word	dkstatement_while
.string "wend"							; WEND
.word	dkstatement_wend
.string "poke"							; POKE
.word	dkstatement_poke
.string "list"							; LIST
.word	dkstatement_list
.string "run"							; RUN
.word	dkstatement_run
.string "goto"							; GOTO
.word	dkstatement_goto
.string "gosub"							; GOSUB
.word	dkstatement_gosub
.string "return"						; RETURN
.word	dkstatement_return
.string "stop"							; STOP
.word	dkstatement_stop
.string "cont"							; CONT
.word	dkstatement_cont
.string "end"							; END
.word	dkstatement_end
.string "delay"							;+DELAY
.word	dkstatement_delay
.string "tron"							; TRON
.word	dkstatement_tron
.string "troff"							; TROFF
.word	dkstatement_troff
.string "save"
.word	dkstatement_save				; SAVE
.string "load"
.word	dkstatement_load				; LOAD
.string "clear"
.word	dkstatement_clear				; CLEAR
.string "new"
.word	dkstatement_new					; NEW
.string "edit"
.word	dkstatement_edit				; EDIT
.string "varlist"						;+VARLIST
.word	dkstatement_varlist
;.string "keyled"						;+KEYLED
;.word	dkstatement_keyled
.string "heap"	
.word	dkstatement_heap
.string "locate"	
.word	dkstatement_locate
.string "cls"	
.word	dkstatement_cls
.string "open"	
.word	dkstatement_open
.string "close"	
.word	dkstatement_close
.string "on"	
.word	dkstatement_on
.string "com"	
.word	dkstatement_com
.string "timer"
.word	dkstatement_timer
.string "pin"
.word	dkstatement_pin
.string "term"
.word	dkstatement_term
.string "byter"
.word   dkstatement_byter
.string "bytew"
.word   dkstatement_bytew
.string "byterw"
.word   dkstatement_byterw

.byte	0								; end interp_keywords with an empty string (NULL)


.align 2								; code must be aligned on word boundary


;---------------------------------------------------------------------
; dkfindstatement
; r25:r24 in = ptr to string in ram
; r25:r24 out = ptr to statment handler function
; note: side effect: string is converted to lowercase

.func dkfindstatement
.global dkfindstatement
dkfindstatement:
	ldi		r23, hi8(dkstatementtable)	; dkstatementtable in FLASH is a list of names and matching functions
	ldi		r22, lo8(dkstatementtable)

	call	dksearchtable

	lsr		r25							; shift address to the right (adjust from byte address to word address)
	ror		r24

	ret

.endfunc


;---------------------------------------------------------------------

